package cn.weiron.fun.schedule;


import cn.weiron.fun.sample.entity.SamplePoint;
import cn.weiron.fun.sample.service.SamplePointService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.List;

/**
 * @author weiRon
 * @date 2022/9/27 18:00
 */
@Service
@Slf4j
public class ImageService {

    public ImageService(@Qualifier("samplePointServiceImpl") SamplePointService samplePointService) {
        this.samplePointService = samplePointService;
    }

    /**
     * 服务对象
     */
    private final SamplePointService samplePointService;


    public void createBatchQrCode(int index){
        Page page = new Page(index,100);
        List<SamplePoint> points = samplePointService.page(page).getRecords();
        if(points.size()==0){
            return ;
        }
        String backgroundPath = "E:\\testData\\点位二维码.jpg";
        String codeFile = "E:\\testData\\code\\";

        points.forEach(point->{
            String savePath = "E:\\testData\\二维码\\"+point.getStreet()+"\\"+point.getCommunity()+"\\"+point.getId()+"-"+point.getName()+".jpg";
            String name= "1111";
            savePath=savePath.replaceAll(" ","");
            try {
                ImageUtil.createCode(backgroundPath,codeFile+point.getId()+".JPG",point.getName(),point.getAddress(),name,savePath);
            } catch (IOException e) {
                e.printStackTrace();
                log.error("图片拼接异常");
            }
        });
    }




}
